package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Inventory;
import com.ruoyi.system.service.IInventoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * Inventory 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-06
 */
@Controller
@RequestMapping("/system/inventory")
public class InventoryController extends BaseController
{
    private String prefix = "system/inventory";
	
	@Autowired
	private IInventoryService inventoryService;
	
	@RequiresPermissions("system:inventory:view")
	@GetMapping()
	public String inventory()
	{
	    return prefix + "/inventory";
	}
	
	/**
	 * 查询Inventory列表
	 */
	@RequiresPermissions("system:inventory:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Inventory inventory)
	{
		startPage();
        List<Inventory> list = inventoryService.selectInventoryList(inventory);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出Inventory列表
	 */
	@RequiresPermissions("system:inventory:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Inventory inventory)
    {
    	List<Inventory> list = inventoryService.selectInventoryList(inventory);
        ExcelUtil<Inventory> util = new ExcelUtil<Inventory>(Inventory.class);
        return util.exportExcel(list, "inventory");
    }
	
	/**
	 * 新增Inventory
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存Inventory
	 */
	@RequiresPermissions("system:inventory:add")
	@Log(title = "Inventory", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Inventory inventory)
	{		
		return toAjax(inventoryService.insertInventory(inventory));
	}

	/**
	 * 修改Inventory
	 */
	@GetMapping("/edit/{productId}")
	public String edit(@PathVariable("productId") Integer productId, ModelMap mmap)
	{
		Inventory inventory = inventoryService.selectInventoryById(productId);
		mmap.put("inventory", inventory);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存Inventory
	 */
	@RequiresPermissions("system:inventory:edit")
	@Log(title = "Inventory", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Inventory inventory)
	{		
		return toAjax(inventoryService.updateInventory(inventory));
	}
	
	/**
	 * 删除Inventory
	 */
	@RequiresPermissions("system:inventory:remove")
	@Log(title = "Inventory", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(inventoryService.deleteInventoryByIds(ids));
	}
	
}
